﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    public class QuitCommand : Command, ICommandInfo
    {
        public override string HelpText { get { return "Saves your character and exits the game.  Not currently implemented"; } }        

        [NonSerialized, XmlIgnore]
        public static List<string> Words = new List<string>() { "QUIT" };

        public override List<string> FirstWords { get { return Words; } }

        public override CommandToPerform CreateCommand(IGameThing source, string first, string input)
        {
            return new CommandToPerform(source.AssociatedID, input) { PerformInfo = "QuitCommand.PerformQuit" };
        }

        [MethodVisible]
        public static List<PerceivedEventAndAudience> PerformQuit(CommandToPerform cmd, IGameThing source, IGameThing target, PropertyData args, PropertyData modifyingArguments)
        {
            List<PerceivedEventAndAudience> events = new List<PerceivedEventAndAudience>();
            GameThingBaseClass sourceChar = source as GameThingBaseClass;
            string quitParams = (cmd.UserInput == null) ? string.Empty : cmd.UserInput;
            string[] strings = quitParams.Split(" ".ToCharArray(), 2, StringSplitOptions.None);

            // TODO: Save character, leave game
            EventToPerceive evt = CreateQuitObservable(source as IAssociatedID);
            events.Add(new PerceivedEventAndAudience() { Event = evt, Audience = sourceChar.GameLocation.Things });

            return events;
        }

        [MethodVisible]
        public static EventToPerceive CreateQuitObservable(IAssociatedID source)
        {
            return new GeneralEventToPerceive()
            {
                ShowToObservers = new Event(string.Format("~source has left the game."), ViewType.See),
                ShowToSource = new Event(string.Format("You leave the game."), ViewType.See),
                Sources = new AssociatedIDCollection(source.AssociatedID)
            };
        }
    }
}
